package com.baidu.jiuhao.es.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.http.ResponseEntity;

// 统一响应类（泛型设计）
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {
    private Integer code;    // 状态码
    private String msg;      // 消息描述
    private T data;         // 响应数据

    // 快速构建成功响应
    public static <T> ResponseEntity<Result<T>> success(T data) {
        return ResponseEntity.ok(
                new Result<>(200, "success", data)
        );
    }

    // 快速构建失败响应
    public static <T> ResponseEntity<Result<T>> error(int code, String msg) {
        return ResponseEntity.status(code).body(
                new Result<>(code, msg, null)
        );
    }
}
